package com.wskeee.ec.containers
{
	import flash.display.DisplayObject;
	import flash.events.Event;

	public class VBox extends Box
	{
		public function VBox()
		{
			super();
			_direction = VERTICAL;
		}
		
		//========================= validate ====================
		override protected function measure():void
		{
			super.measure();
			measureWidth = _paddingLeft + _paddingRight + maxItemWidth;
			measureHeight = _paddingTop + _paddingBottom + Math.max(numChildren-1,0)*_verticalGap + contentHeight;
		}
		override protected function updateDisplayList():void
		{
			super.updateDisplayList();
			
			var maxWidth:Number = (!isNaN(width)) ? width : measureWidth;
			var maxHeight:Number = (!isNaN(height)) ? height : measureHeight;
			
			var ypos:Number;
			var xpos:Number = _paddingLeft;
			var child:DisplayObject;
			
			borderDrawer.lineStyle(0.1,borderColor as uint,0.5);
			
			switch(verticalAlign)
			{
				case LayoutConst.TOP:
					ypos = _paddingTop;
					break;	
				case LayoutConst.MIDDLE:
					ypos = (maxHeight - measureHeight)/2;
					break;	
				case LayoutConst.BOTTOM:
					ypos = maxHeight - measureHeight;
					break;	
				
			}
			
			for(var i:int = 0; i < numChildren; i++)
			{
				child = getChildAt(i);
				child.y = ypos;
				switch(horizontalAlign)
				{
					case LayoutConst.LEFT:
						child.x = xpos;
						break;	
					case LayoutConst.CENTER:
						child.x = (maxWidth- child.width)/2;
						break;
					case LayoutConst.RIGHT:
						child.x = maxWidth - child.width - _paddingRight;
						break;
				}
				ypos += child.height + _verticalGap;
				
				if(border)
					borderDrawer.drawRect(_paddingLeft,child.y,maxWidth - _paddingLeft - _paddingRight,child.height);
			}
			if(border)
				borderDrawer.drawRect(0,0,maxWidth,maxHeight);
			
			if(isNaN(width) || isNaN(height))
				setActualSize(maxWidth,maxHeight,false);
			
			if(oldMeasureWidth!=measureWidth || oldMeasureHeight!=measureHeight)
				dispatchEvent(new Event(Event.RESIZE));
		}
		//========================= end =========================
	}
}